

var ip_addr = ''

function getLocalIP() {
    var RTCPeerConnection = window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection;

    if (RTCPeerConnection) {
        var rtc = new RTCPeerConnection({ iceServers: [] });
        rtc.createDataChannel('', { reliable: false });
        rtc.onicecandidate = function (evt) {
            if (evt.candidate) {
                var ip_regex = /([0-9]{1,3}(\.[0-9]{1,3}){3})/;
                ip_addr = ip_regex.exec(evt.candidate.candidate)[1];
                console.log('Local IP Address: ' + ip_addr);
                rtc.onicecandidate = null;
            }
        };
        rtc.createOffer(function (offerDesc) {
            rtc.setLocalDescription(offerDesc);
        }, function (e) { console.warn('oops... something went wrong: ' + e); });
    } else {
        console.log('The RTCPeerConnection is not supported by this browser.');
    }
}

getLocalIP();



var IpUrl = "http://192.168.0.74:9003";
var baseUrl = "http://150.158.114.51:80/api/";

function http(url, method = 'get', data) {
    return axios({
        url: baseUrl + url,
        method,
        data,
        headers: {
            'Content-Language': 'Chinese (Simplified)',
            'Client-Type': 'seashineWeb',
            'App-Ver': '2.0.0',
            'X-Real-IP': 'http://' + ip_addr,
            'Authorization': localStorage.getItem('token') || '',
            'Customer-ID': localStorage.getItem('customerid') || ''

        },
    }).then(res => {
        // console.log(res.data);
        if (res.data.status == 50 || res.data.status == -2) {
            localStorage.clear()
            console.log(location.pathname);
            if (location.pathname == '/html/qqyxk.html'
                || location.pathname == '/html/znxxxt.html' || location.pathname == '/html/znxxxtSearch.html'
                || location.pathname == '/html/znxxxtSimple.html' || location.pathname == '/html/memberLogin.html'
                || location.pathname == '/html/customize.html' || location.pathname == '/html/user.html'
                || location.pathname == '/html/qqyxkError.html' || location.pathname == '/html/znxxxtError.html'
            ) {
                location.href = './login.html'
            }

        } else {
            return res.data
            // this.$message.err(res.data.message)
        }


    }).catch(err => {
        // console.log('err', err);
        // return err.data
    })
}





// export function http(url, method = 'get', data) {
//     return instance.get(url, { params });
// }